package com.situ.mall.order.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.situ.mall.common.util.Result;
import com.situ.mall.order.entity.query.OrderInfoQuery;
import com.situ.mall.order.entity.vo.OrderInfoVO;
import com.situ.mall.order.service.IOrderInfoService;
import com.situ.mall.pojo.entity.order.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author Gao
 * @since 2024-10-16
 */
@RestController
@RequestMapping("/order/orderInfo")
public class OrderInfoController {
    @Autowired
    private IOrderInfoService orderInfoService;


    @PostMapping("/add")
    public Result add(@RequestBody OrderInfo orderInfo) {
        //orderInfo里面有userId和addressId
        orderInfoService.add(orderInfo);
        return Result.ok("添加成功");
    }

    @GetMapping("/list")
    @RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST})
    public Result<IPage<OrderInfoVO>>list(OrderInfoQuery orderInfoQuery) {
        IPage<OrderInfoVO> page = orderInfoService.list(orderInfoQuery);
        return Result.ok(page);
    }

    @PutMapping("/updateStatus")
    public Result updateStatus(@RequestBody OrderInfo orderInfo) {
        orderInfoService.updateStatus(orderInfo);
        return Result.ok("更新成功");
    }

    @GetMapping("/payOrder")
    public Result payOrder(Long userId, Long orderId) {
        orderInfoService.payOrder(userId, orderId);
        return Result.ok("支付成功");
    }
}

